﻿CREATE PROCEDURE smenu_Tracker__UnInstall
	@TrackerRequestID int
AS ---PRINT OBJECT_NAME(@@PROCID)

/**/DECLARE @CI int EXEC @CI = sp__Context_WorkFlow_System 1
UPDATE t_Tracker
SET StatusID = CASE dbo.TrackerStatusBack(ID)
							 WHEN dbo.Tracker_Status__ToBeReturned()
							 THEN dbo.Tracker_Status__ToBeReturned()
							 ELSE dbo.Tracker_Status__InHands()
							 END
WHERE ID IN (SELECT TrackerID FROM t_Tracker_Car WHERE TrackerRequestID = @TrackerRequestID)
/**/IF @@ERROR <> 0 BEGIN ROLLBACK TRAN RETURN END
		ELSE EXEC sp__Context @CI

RETURN -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

IF @@ROWCOUNT = 0 BEGIN
	ROLLBACK TRAN
	RAISERROR('To trackers were uninstalled.',16,1)
	RETURN
END





